<template>
  <div style="display: flex;flex-direction: column;width: 100%">
    <Header :activeName="activeName"></Header>
    <div class="home-banner"></div>
    <main class="main">
      <div class="home-m" style="background-color: #eeeeee">
        <div class="course-title-container">
          <span class="course-title">健身课程</span>
        </div>
        <div class="home-carousel">
          <el-carousel :interval="4000" type="card" :autoplay="true">
            <el-carousel-item v-for="item in categoryData" :key="item.id"> >
              <div class="home-carousel-item">
                <img :src="item.pic" alt="瑜伽"/>
                <h3>{{item.name}}</h3>
              </div>
            </el-carousel-item>
          </el-carousel>
        </div>
      </div>
      <div class="home-m" style="background-color: #eeeeee">
        <div class="course-title-container">
          <span class="course-title">新闻中心</span>
        </div>
        <div class="news-container">
          <div style="display: flex;align-items: center;flex-direction: column;">
            <a class="news-content" v-for="item in newsData" :key="item.id" :href="'/news/detail?nid=' + item.id">
              <img :src="item.pic" :alt="item.title"
                   style="width:20%;height: 170px;object-fit: cover" >
              <div style="width: 20%" class="news-p-c">
                <p class="title">{{item.title}}</p>
                <p v-html="item.content" class="content"></p>
                <p class="comment">发布日期：{{item.updateTime}}</p>
              </div>
            </a>
          </div>

        </div>
      </div>
    </main>
    <BackTop></BackTop>
    <Footer></Footer>
  </div>

</template>

<script setup lang="ts">
import Header from '@/components/header/Header.vue'
import Footer from '@/components/header/Footer.vue'
import BackTop from '@/components/BackTop.vue'
// import LatestGoods from '@/components/indexDecorate/decorateList/LatestGoods.vue'

import {onMounted, ref} from 'vue'
import {useRouter} from "vue-router";
import {indexCategory} from "@/api/course.ts";
import {indexNews} from "@/api/news.ts";

const router = useRouter()
const activeName = router.currentRoute.value.path

const showNav = ref(true)
const carouselLarge = ref(true)
const carouselOpacity = ref(true)
const baseUrl = import.meta.env.VITE_PIC_URL
const categoryData = ref([])
const newsData = ref([])

onMounted(()=>{
  indexCategory().then((res)=>{
    categoryData.value = res.data
  })
  indexNews().then((res)=>{
    newsData.value = res.data
  })
})

</script>
<style scoped>
.bg {
  background: url("@/assets/home-bg.jpg") center center no-repeat;
  height: 100vh;
  width: 100vw;
  background-size: 100% 100%;
  /*position: absolute;*/
}
.main {
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  margin-top: 10px;
  flex-direction: column;
}
.home-m {
  width: 100%;
  min-height: 500px;
  margin-bottom: 5px;
}
.home-banner {
/*  width: 100%;
  height: 500px;*/
  border: 1px solid #222222;
  background: url("@/assets/banner.jpeg") center center no-repeat;
  height: 100vh;
  width: 100%;
  background-size: 100% 100%;
}

.course-title-container {
  height: 65px;
  display: flex;
  justify-content: center;
}
.course-title {
  font-size: 30px;
  display: inline-block;
  color: #000000;
  position: relative;
}
.course-title::after {
  content: "";
  width: 40px;
  height: 1px;
  background-color: #000;
  position: absolute;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
}
.home-carousel {
  text-align: center;
  margin-top: 5px;
}
.home-carousel-item {
  position: relative;
  height: 100%;
}
.home-carousel-item:hover{
  cursor: pointer;
}

.home-carousel-item h3 {
  position: absolute;
  left: 20%;
  bottom: 10%;
  color: #000;
  font-size: 30px;
}
.news-container {
  width: 100%;
  display: flex;
  justify-content: center;
  margin-top: 10px;
}
.news-content{
  width: 80%;
  display: flex;
  justify-content: space-between;
  border-bottom: 1px dashed #000000;
  margin-top: 15px;
}
.news-p-c {
  padding: 0 10px;
  flex-grow: 1;
}
.news-p-c p {
  font-size: 18px;
}
.news-p-c p.title {
  color: #000000;
  font-size: 22px;
  font-weight: bold;
  text-align: center;
}
.news-p-c p.content {
  color: #000000;
  font-size: 18px;
  height: 110px;
  overflow: hidden;
  text-overflow: ellipsis;
}
.news-p-c img {
  width: 100px;
  height: 100px;
  object-fit: cover;
}
.news-p-c p.comment {
  height: 20px;
  line-height: 20px;
  color: #000000;
}
</style>
